let redis = require('redis');

const options = {
    url: 'redis://39.104.93.152:8379',
    password: '123456'

}
const redisClient = redis.createClient(options)


const message = 'redis'
const listenForMessages = () => {
    console.log('listen message 000'+message)
    redisClient.brPop(message, 0, (err, [list, message]) => {
        if (err) {
            console.error('监听消息失败：', err);
            return;
        }
        console.log(`从列表 ${list} 接收到消息：${message}`);
        // 处理消息或执行任何其他操作
        // ...
        // 继续监听新的消息
        listenForMessages();
    })

}

// 连接成功时的回调
redisClient.on('connect', () => {
    listenForMessages();
    console.log('Connected to Redis server !');
});


// 连接错误时的回调
redisClient.on('error', (error) => {
    console.error('Failed to connect to Redis server:', error);
});
redisClient.connect();


